home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / emacssrc.zip / EMACSSRC.TAR / emacs-19.17 / src / frame.c < prev    next >
C/C++ Source or Header  |  1993-10-07  |  49KB  |  1,695 lines

  1. /* Generic frame functions.
  2.    Copyright (C) 1993 Free Software Foundation.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <stdio.h>
  21.  
  22. #include "config.h"
  23. #include "lisp.h"
  24. #include "frame.h"
  25.  
  26. #ifdef MULTI_FRAME
  27.  
  28. #include "buffer.h"
  29. #include "window.h"
  30. #include "termhooks.h"
  31.  
  32. /* These help us bind and responding to switch-frame events.  */
  33. #include "commands.h"
  34. #include "keyboard.h"
  35.  
  36. #ifdef STDC_HEADERS
  37. #include <stdlib.h>
  38. #endif
  39. #include "frame_p.h"
  40. #include "dispnew_d.h"
  41.  
  42. Lisp_Object Vemacs_iconified;
  43. Lisp_Object Vframe_list;
  44. Lisp_Object Vterminal_frame;
  45. Lisp_Object Vdefault_minibuffer_frame;
  46. Lisp_Object Vdefault_frame_alist;
  47.  
  48. /* Evaluate this expression to rebuild the section of syms_of_frame
  49.    that initializes and staticpros the symbols declared below.  Note
  50.    that Emacs 18 has a bug that keeps C-x C-e from being able to
  51.    evaluate this expression.
  52.  
  53. (progn
  54.   ;; Accumulate a list of the symbols we want to initialize from the
  55.   ;; declarations at the top of the file.
  56.   (goto-char (point-min))
  57.   (search-forward "/\*&&& symbols declared here &&&*\/\n")
  58.   (let (symbol-list)
  59.     (while (looking-at "Lisp_Object \\(Q[a-z_]+\\)")
  60.       (setq symbol-list
  61.         (cons (buffer-substring (match-beginning 1) (match-end 1))
  62.           symbol-list))
  63.       (forward-line 1))
  64.     (setq symbol-list (nreverse symbol-list))
  65.     ;; Delete the section of syms_of_... where we initialize the symbols.
  66.     (search-forward "\n  /\*&&& init symbols here &&&*\/\n")
  67.     (let ((start (point)))
  68.       (while (looking-at "^  Q")
  69.     (forward-line 2))
  70.       (kill-region start (point)))
  71.     ;; Write a new symbol initialization section.
  72.     (while symbol-list
  73.       (insert (format "  %s = intern (\"" (car symbol-list)))
  74.       (let ((start (point)))
  75.     (insert (substring (car symbol-list) 1))
  76.     (subst-char-in-region start (point) ?_ ?-))
  77.       (insert (format "\");\n  staticpro (&%s);\n" (car symbol-list)))
  78.       (setq symbol-list (cdr symbol-list)))))
  79.   */        
  80.  
  81. /*&&& symbols declared here &&&*/
  82. Lisp_Object Qframep;
  83. Lisp_Object Qframe_live_p;
  84. Lisp_Object Qheight;
  85. Lisp_Object Qicon;
  86. Lisp_Object Qminibuffer;
  87. Lisp_Object Qmodeline;
  88. Lisp_Object Qname;
  89. Lisp_Object Qonly;
  90. Lisp_Object Qunsplittable;
  91. Lisp_Object Qmenu_bar_lines;
  92. Lisp_Object Qwidth;
  93. Lisp_Object Qx;
  94.  
  95. extern Lisp_Object Vminibuffer_list;
  96.  
  97. DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
  98.   "Return non-nil if OBJECT is a frame.\n\
  99. Value is t for a termcap frame (a character-only terminal),\n\
  100. `x' for an Emacs frame that is really an X window.\n\
  101. Also see `live-frame-p'.")
  102.   (object)
  103.      Lisp_Object object;
  104. {
  105.   if (XTYPE (object) != Lisp_Frame)
  106.     return Qnil;
  107.   switch (XFRAME (object)->output_method)
  108.     {
  109.     case output_termcap:
  110.       return Qt;
  111.     case output_x_window:
  112.       return Qx;
  113.     default:
  114.       abort ();
  115.     }
  116. }
  117.  
  118. DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
  119.   "Return non-nil if OBJECT is a frame which has not been deleted.\n\
  120. Value is nil if OBJECT is not a live frame.  If object is a live\n\
  121. frame, the return value indicates what sort of output device it is\n\
  122. displayed on.  Value is t for a termcap frame (a character-only\n\
  123. terminal), `x' for an Emacs frame being displayed in an X window.")
  124.   (object)
  125.      Lisp_Object object;
  126. {
  127.   return ((FRAMEP (object)
  128.        && FRAME_LIVE_P (XFRAME (object)))
  129.       ? Fframep (object)
  130.       : Qnil);
  131. }
  132.  
  133. struct frame *
  134. make_frame (mini_p)
  135.      int mini_p;
  136. {
  137.   Lisp_Object frame;
  138.   register struct frame *f;
  139.   register Lisp_Object root_window;
  140.   register Lisp_Object mini_window;
  141.  
  142.   frame = Fmake_vector (((sizeof (struct frame) - (sizeof (Lisp_Vector)
  143.                              - sizeof (Lisp_Object)))
  144.               / sizeof (Lisp_Object)),
  145.              make_number (0));
  146.   XSETTYPE (frame, Lisp_Frame);
  147.   f = XFRAME (frame);
  148.  
  149.   f->cursor_x = 0;
  150.   f->cursor_y = 0;
  151.   f->current_glyphs = 0;
  152.   f->desired_glyphs = 0;
  153.   f->visible = 0;
  154.   f->async_visible = 0;
  155.   f->display.nothing = 0;
  156.   f->iconified = 0;
  157.   f->async_iconified = 0;
  158.   f->wants_modeline = 1;
  159.   f->auto_raise = 0;
  160.   f->auto_lower = 0;
  161.   f->no_split = 0;
  162.   f->garbaged = 0;
  163.   f->has_minibuffer = mini_p;
  164.   f->focus_frame = Qnil;
  165.   f->explicit_name = 0;
  166.   f->can_have_scroll_bars = 0;
  167.   f->has_vertical_scroll_bars = 0;
  168.   f->param_alist = Qnil;
  169.   f->scroll_bars = Qnil;
  170.   f->condemned_scroll_bars = Qnil;
  171.   f->face_alist = Qnil;
  172.  
  173.   root_window = make_window ();
  174.   if (mini_p)
  175.     {
  176.       mini_window = make_window ();
  177.       XWINDOW (root_window)->next = mini_window;
  178.       XWINDOW (mini_window)->prev = root_window;
  179.       XWINDOW (mini_window)->mini_p = Qt;
  180.       XWINDOW (mini_window)->frame = frame;
  181.       f->minibuffer_window = mini_window;
  182.     }
  183.   else
  184.     {
  185.       mini_window = Qnil;
  186.       XWINDOW (root_window)->next = Qnil;
  187.       f->minibuffer_window = Qnil;
  188.     }
  189.  
  190.   XWINDOW (root_window)->frame = frame;
  191.  
  192.   /* 10 is arbitrary,
  193.      just so that there is "something there."
  194.      Correct size will be set up later with change_frame_size.  */
  195.  
  196.   f->width = 10;
  197.   f->height = 10;
  198.  
  199.   XFASTINT (XWINDOW (root_window)->width) = 10;
  200.   XFASTINT (XWINDOW (root_window)->height) = (mini_p ? 9 : 10);
  201.  
  202.   if (mini_p)
  203.     {
  204.       XFASTINT (XWINDOW (mini_window)->width) = 10;
  205.       XFASTINT (XWINDOW (mini_window)->top) = 9;
  206.       XFASTINT (XWINDOW (mini_window)->height) = 1;
  207.     }
  208.  
  209.   /* Choose a buffer for the frame's root window.  */
  210.   {
  211.     Lisp_Object buf;
  212.  
  213.     XWINDOW (root_window)->buffer = Qt;
  214.     buf = Fcurrent_buffer ();
  215.     /* If buf is a 'hidden' buffer (i.e. one whose name starts with
  216.        a space), try to find another one.  */
  217.     if (XSTRING (Fbuffer_name (buf))->data[0] == ' ')
  218.       buf = Fother_buffer (buf, Qnil);
  219.     Fset_window_buffer (root_window, buf);
  220.   }
  221.  
  222.   if (mini_p)
  223.     {
  224.       XWINDOW (mini_window)->buffer = Qt;
  225.       Fset_window_buffer (mini_window,
  226.               (NILP (Vminibuffer_list)
  227.                ? get_minibuffer (0)
  228.                : Fcar (Vminibuffer_list)));
  229.     }
  230.  
  231.   f->root_window = root_window;
  232.   f->selected_window = root_window;
  233.   /* Make sure this window seems more recently used than
  234.      a newly-created, never-selected window.  */
  235.   XFASTINT (XWINDOW (f->selected_window)->use_time) = ++window_select_count;
  236.  
  237.   Vframe_list = Fcons (frame, Vframe_list);
  238.  
  239.   return f;
  240. }
  241.  
  242. /* Make a frame using a separate minibuffer window on another frame.
  243.    MINI_WINDOW is the minibuffer window to use.  nil means use the
  244.    default (the global minibuffer).  */
  245.  
  246. struct frame *
  247. make_frame_without_minibuffer (mini_window)
  248.      register Lisp_Object mini_window;
  249. {
  250.   register struct frame *f;
  251.  
  252.   /* Choose the minibuffer window to use.  */
  253.   if (NILP (mini_window))
  254.     {
  255.       if (XTYPE (Vdefault_minibuffer_frame) != Lisp_Frame)
  256.     error ("default-minibuffer-frame must be set when creating minibufferless frames");
  257.       if (! FRAME_LIVE_P (XFRAME (Vdefault_minibuffer_frame)))
  258.     error ("default-minibuffer-frame must be a live frame");
  259.       mini_window = XFRAME (Vdefault_minibuffer_frame)->minibuffer_window;
  260.     }
  261.   else
  262.     {
  263.       CHECK_LIVE_WINDOW (mini_window, 0);
  264.     }
  265.  
  266.   /* Make a frame containing just a root window.  */
  267.   f = make_frame (0);
  268.  
  269.   /* Install the chosen minibuffer window, with proper buffer.  */
  270.   f->minibuffer_window = mini_window;
  271.   Fset_window_buffer (mini_window,
  272.               (NILP (Vminibuffer_list)
  273.                ? get_minibuffer (0)
  274.                : Fcar (Vminibuffer_list)));
  275.   return f;
  276. }
  277.  
  278. /* Make a frame containing only a minibuffer window.  */
  279.  
  280. struct frame *
  281. make_minibuffer_frame ()
  282. {
  283.   /* First make a frame containing just a root window, no minibuffer.  */
  284.  
  285.   register struct frame *f = make_frame (0);
  286.   register Lisp_Object mini_window;
  287.   register Lisp_Object frame;
  288.  
  289.   XSET (frame, Lisp_Frame, f);
  290.  
  291.   f->auto_raise = 0;
  292.   f->auto_lower = 0;
  293.   f->no_split = 1;
  294.   f->wants_modeline = 0;
  295.   f->has_minibuffer = 1;
  296.  
  297.   /* Now label the root window as also being the minibuffer.
  298.      Avoid infinite looping on the window chain by marking next pointer
  299.      as nil. */
  300.  
  301.   mini_window = f->minibuffer_window = f->root_window;
  302.   XWINDOW (mini_window)->mini_p = Qt;
  303.   XWINDOW (mini_window)->next = Qnil;
  304.   XWINDOW (mini_window)->prev = Qnil;
  305.   XWINDOW (mini_window)->frame = frame;
  306.  
  307.   /* Put the proper buffer in that window.  */
  308.  
  309.   Fset_window_buffer (mini_window,
  310.               (NILP (Vminibuffer_list)
  311.                ? get_minibuffer (0)
  312.                : Fcar (Vminibuffer_list)));
  313.   return f;
  314. }
  315.  
  316. /* Construct a frame that refers to the terminal (stdin and stdout).  */
  317.  
  318. struct frame *
  319. make_terminal_frame ()
  320. {
  321.   register struct frame *f;
  322.  
  323.   Vframe_list = Qnil;
  324.   f = make_frame (1);
  325.   f->name = build_string ("terminal");
  326.   FRAME_SET_VISIBLE (f, 1);
  327.   f->display.nothing = 1;   /* Nonzero means frame isn't deleted.  */
  328.   XSET (Vterminal_frame, Lisp_Frame, f);
  329.   return f;
  330. }
  331.  
  332. DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
  333.   "Select the frame FRAME.\n\
  334. Subsequent editing commands apply to its selected window.\n\
  335. The selection of FRAME lasts until the next time the user does\n\
  336. something to select a different frame, or until the next time this\n\
  337. function is called.")
  338.   (frame, no_enter)
  339.     Lisp_Object frame, no_enter;
  340. {
  341.   return Fhandle_switch_frame (frame, no_enter);
  342. }
  343.  
  344.  
  345. DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 2, "e",
  346.   "Handle a switch-frame event EVENT.\n\
  347. Switch-frame events is usually bound to this function.\n\
  348. A switch-frame event tells Emacs that the window manager has requested\n\
  349. that the user's events be directed to the frame mentioned in the event.\n\
  350. This function selects the selected window of the frame of EVENT.\n\
  351. \n\
  352. If EVENT is frame object, handle it as if it were a switch-frame event\n\
  353. to that frame.")
  354.   (frame, no_enter)
  355.      Lisp_Object frame, no_enter;
  356. {
  357.   /* If FRAME is a switch-frame event, extract the frame we should
  358.      switch to.  */
  359.   if (CONSP (frame)
  360.       && EQ (XCONS (frame)->car, Qswitch_frame)
  361.       && CONSP (XCONS (frame)->cdr))
  362.     frame = XCONS (XCONS (frame)->cdr)->car;
  363.  
  364.   CHECK_LIVE_FRAME (frame, 0);
  365.  
  366.   if (selected_frame == XFRAME (frame))
  367.     return frame;
  368.  
  369.   /* If a frame's focus has been redirected toward the currently
  370.      selected frame, we should change the redirection to point to the
  371.      newly selected frame.  This means that if the focus is redirected
  372.      from a minibufferless frame to a surrogate minibuffer frame, we
  373.      can use `other-window' to switch between all the frames using
  374.      that minibuffer frame, and the focus redirection will follow us
  375.      around.  */
  376.   {
  377.     Lisp_Object tail;
  378.  
  379.     for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
  380.       {
  381.     Lisp_Object focus;
  382.  
  383.     if (XTYPE (XCONS (tail)->car) != Lisp_Frame)
  384.       abort ();
  385.  
  386.     focus = FRAME_FOCUS_FRAME (XFRAME (XCONS (tail)->car));
  387.  
  388.     if (XTYPE (focus) == Lisp_Frame
  389.         && XFRAME (focus) == selected_frame)
  390.       Fredirect_frame_focus (XCONS (tail)->car, frame);
  391.       }
  392.   }
  393.  
  394.   selected_frame = XFRAME (frame);
  395.   if (! FRAME_MINIBUF_ONLY_P (selected_frame))
  396.     last_nonminibuf_frame = selected_frame;
  397.  
  398.   Fselect_window (XFRAME (frame)->selected_window);
  399.   choose_minibuf_frame ();
  400.  
  401.   /* We want to make sure that the next event generates a frame-switch
  402.      event to the appropriate frame.  This seems kludgy to me, but
  403.      before you take it out, make sure that evaluating something like
  404.      (select-window (frame-root-window (new-frame))) doesn't end up
  405.      with your typing being interpreted in the new frame instead of
  406.      the one you're actually typing in.  */
  407.   internal_last_event_frame = Qnil;
  408.  
  409.   return frame;
  410. }
  411.  
  412. DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
  413.   "Return the frame that is now selected.")
  414.   ()
  415. {
  416.   Lisp_Object tem;
  417.   XSET (tem, Lisp_Frame, selected_frame);
  418.   return tem;
  419. }
  420.  
  421. DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
  422.   "Return the frame object that window WINDOW is on.")
  423.   (window)
  424.      Lisp_Object window;
  425. {
  426.   CHECK_LIVE_WINDOW (window, 0);
  427.   return XWINDOW (window)->frame;
  428. }
  429.  
  430. DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
  431.        "Returns the root-window of FRAME.\n\
  432. If omitted, FRAME defaults to the currently selected frame.")
  433.   (frame)
  434.      Lisp_Object frame;
  435. {
  436.   if (NILP (frame))
  437.     XSET (frame, Lisp_Frame, selected_frame);
  438.   else
  439.     CHECK_LIVE_FRAME (frame, 0);
  440.  
  441.   return XFRAME (frame)->root_window;
  442. }
  443.  
  444. DEFUN ("frame-selected-window", Fframe_selected_window,
  445.        Sframe_selected_window, 0, 1, 0,
  446.   "Return the selected window of frame object FRAME.\n\
  447. If omitted, FRAME defaults to the currently selected frame.")
  448.   (frame)
  449.      Lisp_Object frame;
  450. {
  451.   if (NILP (frame))
  452.     XSET (frame, Lisp_Frame, selected_frame);
  453.   else
  454.     CHECK_LIVE_FRAME (frame, 0);
  455.  
  456.   return XFRAME (frame)->selected_window;
  457. }
  458.  
  459. DEFUN ("frame-list", Fframe_list, Sframe_list,
  460.        0, 0, 0,
  461.        "Return a list of all frames.")
  462.   ()
  463. {
  464.   return Fcopy_sequence (Vframe_list);
  465. }
  466.  
  467. /* Return the next frame in the frame list after FRAME.
  468.    If MINIBUF is nil, exclude minibuffer-only frames.
  469.    If MINIBUF is a window, include only frames using that window for
  470.    their minibuffer.
  471.    If MINIBUF is non-nil, and not a window, include all frames.  */
  472. Lisp_Object
  473. next_frame (frame, minibuf)
  474.      Lisp_Object frame;
  475.      Lisp_Object minibuf;
  476. {
  477.   Lisp_Object tail;
  478.   int passed = 0;
  479.  
  480.   /* There must always be at least one frame in Vframe_list.  */
  481.   if (! CONSP (Vframe_list))
  482.     abort ();
  483.  
  484.   /* If this frame is dead, it won't be in Vframe_list, and we'll loop
  485.      forever.  Forestall that.  */
  486.   CHECK_LIVE_FRAME (frame, 0);
  487.  
  488.   while (1)
  489.     for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
  490.       {
  491.     Lisp_Object f = XCONS (tail)->car;
  492.  
  493.     if (passed)
  494.       {
  495.         /* Decide whether this frame is eligible to be returned.  */
  496.  
  497.         /* If we've looped all the way around without finding any
  498.            eligible frames, return the original frame.  */
  499.         if (EQ (f, frame))
  500.           return f;
  501.  
  502.         /* Let minibuf decide if this frame is acceptable.  */
  503.         if (NILP (minibuf))
  504.           {
  505.         if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
  506.           return f;
  507.           }
  508.         else if (XTYPE (minibuf) == Lisp_Window)
  509.           {
  510.         if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf))
  511.           return f;
  512.           }
  513.         else
  514.           return f;
  515.       }
  516.  
  517.     if (EQ (frame, f))
  518.       passed++;
  519.       }
  520. }
  521.  
  522. /* Return the previous frame in the frame list before FRAME.
  523.    If MINIBUF is nil, exclude minibuffer-only frames.
  524.    If MINIBUF is a window, include only frames using that window for
  525.    their minibuffer.
  526.    If MINIBUF is non-nil and not a window, include all frames.  */
  527. Lisp_Object
  528. prev_frame (frame, minibuf)
  529.      Lisp_Object frame;
  530.      Lisp_Object minibuf;
  531. {
  532.   Lisp_Object tail;
  533.   Lisp_Object prev;
  534.  
  535.   /* There must always be at least one frame in Vframe_list.  */
  536.   if (! CONSP (Vframe_list))
  537.     abort ();
  538.  
  539.   prev = Qnil;
  540.   for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
  541.     {
  542.       Lisp_Object f = XCONS (tail)->car;
  543.  
  544.       if (XTYPE (f) != Lisp_Frame)
  545.     abort ();
  546.  
  547.       if (EQ (frame, f) && !NILP (prev))
  548.     return prev;
  549.  
  550.       /* Decide whether this frame is eligible to be returned,
  551.      according to minibuf.  */
  552.       if (NILP (minibuf))
  553.     {
  554.       if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
  555.         prev = f;
  556.     }
  557.       else if (XTYPE (minibuf) == Lisp_Window)
  558.     {
  559.       if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf))
  560.         prev = f;
  561.     }
  562.       else
  563.     prev = f;
  564.     }
  565.  
  566.   /* We've scanned the entire list.  */
  567.   if (NILP (prev))
  568.     /* We went through the whole frame list without finding a single
  569.        acceptable frame.  Return the original frame.  */
  570.     return frame;
  571.   else
  572.     /* There were no acceptable frames in the list before FRAME; otherwise,
  573.        we would have returned directly from the loop.  Since PREV is the last
  574.        acceptable frame in the list, return it.  */
  575.     return prev;
  576. }
  577.  
  578. DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
  579.   "Return the next frame in the frame list after FRAME.\n\
  580. By default, skip minibuffer-only frames.\n\
  581. If omitted, FRAME defaults to the selected frame.\n\
  582. If optional argument MINIFRAME is non-nil, include minibuffer-only frames.\n\
  583. If MINIFRAME is a window, include only frames using that window for their\n\
  584. minibuffer.\n\
  585. If MINIFRAME is non-nil and not a window, include all frames.")
  586.   (frame, miniframe)
  587.      Lisp_Object frame, miniframe;
  588. {
  589.   if (NILP (frame))
  590.     XSET (frame, Lisp_Frame, selected_frame);
  591.   else
  592.     CHECK_LIVE_FRAME (frame, 0);
  593.  
  594.   return next_frame (frame, miniframe);
  595. }
  596.  
  597.  
  598. DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 1, "",
  599.   "Delete FRAME, permanently eliminating it from use.\n\
  600. If omitted, FRAME defaults to the selected frame.\n\
  601. A frame may not be deleted if its minibuffer is used by other frames.")
  602.   (frame)
  603.      Lisp_Object frame;
  604. {
  605.   struct frame *f;
  606.  
  607.   if (EQ (frame, Qnil))
  608.     {
  609.       f = selected_frame;
  610.       XSET (frame, Lisp_Frame, f);
  611.     }
  612.   else
  613.     {
  614.       CHECK_FRAME (frame, 0);
  615.       f = XFRAME (frame);
  616.     }
  617.  
  618.   if (! FRAME_LIVE_P (f))
  619.     return Qnil;
  620.  
  621.   /* Are there any other frames besides this one?  */
  622.   if (f == selected_frame && EQ (next_frame (frame, Qt), frame))
  623.     error ("Attempt to delete the only frame");
  624.  
  625.   /* Does this frame have a minibuffer, and is it the surrogate
  626.      minibuffer for any other frame?  */
  627.   if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
  628.     {
  629.       Lisp_Object frames;
  630.  
  631.       for (frames = Vframe_list;
  632.        CONSP (frames);
  633.        frames = XCONS (frames)->cdr)
  634.     {
  635.       Lisp_Object this = XCONS (frames)->car;
  636.  
  637.       if (! EQ (this, frame)
  638.           && EQ (frame,
  639.              (WINDOW_FRAME
  640.               (XWINDOW
  641.                (FRAME_MINIBUF_WINDOW
  642.             (XFRAME (this)))))))
  643.         error ("Attempt to delete a surrogate minibuffer frame");
  644.     }
  645.     }
  646.  
  647.   /* Don't let the frame remain selected.  */
  648.   if (f == selected_frame)
  649.     Fhandle_switch_frame (next_frame (frame, Qt), Qnil);
  650.  
  651.   /* Don't allow minibuf_window to remain on a deleted frame.  */
  652.   if (EQ (f->minibuffer_window, minibuf_window))
  653.     {
  654.       Fset_window_buffer (selected_frame->minibuffer_window,
  655.               XWINDOW (minibuf_window)->buffer);
  656.       minibuf_window = selected_frame->minibuffer_window;
  657.     }
  658.  
  659.   /* Mark all the windows that used to be on FRAME as deleted, and then
  660.      remove the reference to them.  */
  661.   delete_all_subwindows (XWINDOW (f->root_window));
  662.   f->root_window = Qnil;
  663.  
  664.   Vframe_list = Fdelq (frame, Vframe_list);
  665.   FRAME_SET_VISIBLE (f, 0);
  666.  
  667.   /* Since some events are handled at the interrupt level, we may get
  668.      an event for f at any time; if we zero out the frame's display
  669.      now, then we may trip up the event-handling code.  Instead, we'll
  670.      promise that the display of the frame must be valid until we have
  671.      called the window-system-dependent frame destruction routine.  */
  672.  
  673.   /* I think this should be done with a hook.  */
  674. #ifdef HAVE_X_WINDOWS
  675.   if (FRAME_X_P (f))
  676.     x_destroy_window (f);
  677. #endif
  678.  
  679.   f->display.nothing = 0;
  680.  
  681.   /* If we've deleted the last_nonminibuf_frame, then try to find
  682.      another one.  */
  683.   if (f == last_nonminibuf_frame)
  684.     {
  685.       Lisp_Object frames;
  686.  
  687.       last_nonminibuf_frame = 0;
  688.  
  689.       for (frames = Vframe_list;
  690.        CONSP (frames);
  691.        frames = XCONS (frames)->cdr)
  692.     {
  693.       f = XFRAME (XCONS (frames)->car);
  694.       if (!FRAME_MINIBUF_ONLY_P (f))
  695.         {
  696.           last_nonminibuf_frame = f;
  697.           break;
  698.         }
  699.     }
  700.     }
  701.  
  702.   /* If we've deleted Vdefault_minibuffer_frame, try to find another
  703.      one.  Prefer minibuffer-only frames, but also notice frames
  704.      with other windows.  */
  705.   if (EQ (frame, Vdefault_minibuffer_frame))
  706.     {
  707.       Lisp_Object frames;
  708.  
  709.       /* The last frame we saw with a minibuffer, minibuffer-only or not.  */
  710.       Lisp_Object frame_with_minibuf = Qnil;
  711.  
  712.       for (frames = Vframe_list;
  713.        CONSP (frames);
  714.        frames = XCONS (frames)->cdr)
  715.     {
  716.       Lisp_Object this = XCONS (frames)->car;
  717.  
  718.       if (XTYPE (this) != Lisp_Frame)
  719.         abort ();
  720.       f = XFRAME (this);
  721.  
  722.       if (FRAME_HAS_MINIBUF_P (f))
  723.         {
  724.           frame_with_minibuf = this;
  725.           if (FRAME_MINIBUF_ONLY_P (f))
  726.         break;
  727.         }
  728.     }
  729.  
  730.       /* We know that there must be some frame with a minibuffer out
  731.      there.  If this were not true, all of the frames present
  732.      would have to be minibufferless, which implies that at some
  733.      point their minibuffer frames must have been deleted, but
  734.      that is prohibited at the top; you can't delete surrogate
  735.      minibuffer frames.  */
  736.       if (NILP (frame_with_minibuf))
  737.     abort ();
  738.  
  739.       Vdefault_minibuffer_frame = frame_with_minibuf;
  740.     }
  741.  
  742.   return Qnil;
  743. }
  744.  
  745. /* Return mouse position in character cell units.  */
  746.  
  747. DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
  748.   "Return a list (FRAME X . Y) giving the current mouse frame and position.\n\
  749. The position is given in character cells, where (0, 0) is the\n\
  750. upper-left corner.\n\
  751. If Emacs is running on a mouseless terminal or hasn't been programmed\n\
  752. to read the mouse position, it returns the selected frame for FRAME\n\
  753. and nil for X and Y.")
  754.   ()
  755. {
  756.   FRAME_PTR f;
  757.   Lisp_Object lispy_dummy;
  758.   enum scroll_bar_part party_dummy;
  759.   Lisp_Object x, y;
  760.   unsigned long long_dummy;
  761.  
  762.   f = selected_frame;
  763.   x = y = Qnil;
  764.  
  765.   /* It's okay for the hook to refrain from storing anything.  */
  766.   if (mouse_position_hook)
  767.     (*mouse_position_hook) (&f,
  768.                 &lispy_dummy, &party_dummy,
  769.                 &x, &y,
  770.                 &long_dummy);
  771.  
  772.   XSET (lispy_dummy, Lisp_Frame, f);
  773.   return Fcons (lispy_dummy, Fcons (x, y));
  774. }
  775.  
  776. DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
  777.   "Move the mouse pointer to the center of character cell (X,Y) in FRAME.\n\
  778. WARNING:  If you use this under X, you should do `unfocus-frame' afterwards.")
  779.   (frame, x, y)
  780.      Lisp_Object frame, x, y;
  781. {
  782.   CHECK_LIVE_FRAME (frame, 0);
  783.   CHECK_NUMBER (x, 2);
  784.   CHECK_NUMBER (y, 1);
  785.  
  786.   /* I think this should be done with a hook.  */
  787. #ifdef HAVE_X_WINDOWS
  788.   if (FRAME_X_P (XFRAME (frame)))
  789.     /* Warping the mouse will cause  enternotify and focus events. */
  790.     x_set_mouse_position (XFRAME (frame), x, y);
  791. #endif
  792.  
  793.   return Qnil;
  794. }
  795.  
  796. DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
  797.        0, 1, "",
  798.   "Make the frame FRAME visible (assuming it is an X-window).\n\
  799. Also raises the frame so that nothing obscures it.\n\
  800. If omitted, FRAME defaults to the currently selected frame.")
  801.   (frame)
  802.      Lisp_Object frame;
  803. {
  804.   if (NILP (frame))
  805.     XSET (frame, Lisp_Frame, selected_frame);
  806.  
  807.   CHECK_LIVE_FRAME (frame, 0);
  808.  
  809.   /* I think this should be done with a hook.  */
  810. #ifdef HAVE_X_WINDOWS
  811.   if (FRAME_X_P (XFRAME (frame)))
  812.     x_make_frame_visible (XFRAME (frame));
  813. #endif
  814.  
  815.   return frame;
  816. }
  817.  
  818. DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
  819.        0, 1, "",
  820.   "Make the frame FRAME invisible (assuming it is an X-window).\n\
  821. If omitted, FRAME defaults to the currently selected frame.")
  822.   (frame)
  823.      Lisp_Object frame;
  824. {
  825.   if (NILP (frame))
  826.     XSET (frame, Lisp_Frame, selected_frame);
  827.  
  828.   CHECK_LIVE_FRAME (frame, 0);
  829.  
  830.   /* Don't let the frame remain selected.  */
  831.   if (XFRAME (frame) == selected_frame)
  832.     Fhandle_switch_frame (next_frame (frame, Qt), Qnil);
  833.  
  834.   /* Don't allow minibuf_window to remain on a deleted frame.  */
  835.   if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
  836.     {
  837.       Fset_window_buffer (selected_frame->minibuffer_window,
  838.               XWINDOW (minibuf_window)->buffer);
  839.       minibuf_window = selected_frame->minibuffer_window;
  840.     }
  841.  
  842.   /* I think this should be done with a hook.  */
  843. #ifdef HAVE_X_WINDOWS
  844.   if (FRAME_X_P (XFRAME (frame)))
  845.     x_make_frame_invisible (XFRAME (frame));
  846. #endif
  847.  
  848.   return Qnil;
  849. }
  850.  
  851. DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
  852.        0, 1, "",
  853.   "Make the frame FRAME into an icon.\n\
  854. If omitted, FRAME defaults to the currently selected frame.")
  855.   (frame)
  856.      Lisp_Object frame;
  857. {
  858.   if (NILP (frame))
  859.     XSET (frame, Lisp_Frame, selected_frame);
  860.   
  861.   CHECK_LIVE_FRAME (frame, 0);
  862.  
  863.   /* Don't let the frame remain selected.  */
  864.   if (XFRAME (frame) == selected_frame)
  865.     Fhandle_switch_frame (next_frame (frame, Qt), Qnil);
  866.  
  867.   /* Don't allow minibuf_window to remain on a deleted frame.  */
  868.   if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
  869.     {
  870.       Fset_window_buffer (selected_frame->minibuffer_window,
  871.               XWINDOW (minibuf_window)->buffer);
  872.       minibuf_window = selected_frame->minibuffer_window;
  873.     }
  874.  
  875.   /* I think this should be done with a hook.  */
  876. #ifdef HAVE_X_WINDOWS
  877.   if (FRAME_X_P (XFRAME (frame)))
  878.       x_iconify_frame (XFRAME (frame));
  879. #endif
  880.  
  881.   return Qnil;
  882. }
  883.  
  884. DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
  885.        1, 1, 0,
  886.        "Return t if FRAME is now \"visible\" (actually in use for display).\n\
  887. A frame that is not \"visible\" is not updated and, if it works through\n\
  888. a window system, it may not show at all.\n\
  889. Return the symbol `icon' if frame is visible only as an icon.")
  890.   (frame)
  891.      Lisp_Object frame;
  892. {
  893.   CHECK_LIVE_FRAME (frame, 0);
  894.  
  895.   if (FRAME_VISIBLE_P (XFRAME (frame)))
  896.     return Qt;
  897.   if (FRAME_ICONIFIED_P (XFRAME (frame)))
  898.     return Qicon;
  899.   return Qnil;
  900. }
  901.  
  902. DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
  903.        0, 0, 0,
  904.        "Return a list of all frames now \"visible\" (being updated).")
  905.   ()
  906. {
  907.   Lisp_Object tail, frame;
  908.   struct frame *f;
  909.   Lisp_Object value;
  910.  
  911.   value = Qnil;
  912.   for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
  913.     {
  914.       frame = XCONS (tail)->car;
  915.       if (XTYPE (frame) != Lisp_Frame)
  916.     continue;
  917.       f = XFRAME (frame);
  918.       if (FRAME_VISIBLE_P (f))
  919.     value = Fcons (frame, value);
  920.     }
  921.   return value;
  922. }
  923.  
  924.  
  925. DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 1, 1, 0,
  926.   "Bring FRAME to the front, so it occludes any frames it overlaps.\n\
  927. If FRAME is invisible, make it visible.\n\
  928. If Emacs is displaying on an ordinary terminal or some other device which\n\
  929. doesn't support multiple overlapping frames, this function does nothing.")
  930.   (frame)
  931.      Lisp_Object frame;
  932. {
  933.   CHECK_LIVE_FRAME (frame, 0);
  934.   
  935.   if (frame_raise_lower_hook)
  936.     (*frame_raise_lower_hook) (XFRAME (frame), 1);
  937.  
  938.   return Qnil;
  939. }
  940.  
  941. /* Should we have a corresponding function called Flower_Power?  */
  942. DEFUN ("lower-frame", Flower_frame, Slower_frame, 1, 1, 0,
  943.   "Send FRAME to the back, so it is occluded by any frames that overlap it.\n\
  944. If Emacs is displaying on an ordinary terminal or some other device which\n\
  945. doesn't support multiple overlapping frames, this function does nothing.")
  946.   (frame)
  947.      Lisp_Object frame;
  948. {
  949.   CHECK_LIVE_FRAME (frame, 0);
  950.   
  951.   if (frame_raise_lower_hook)
  952.     (*frame_raise_lower_hook) (XFRAME (frame), 0);
  953.  
  954.   return Qnil;
  955. }
  956.  
  957.  
  958. DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
  959.        1, 2, 0,
  960.   "Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.\n\
  961. In other words, switch-frame events caused by events in FRAME will\n\
  962. request a switch to FOCUS-FRAME, and `last-event-frame' will be\n\
  963. FOCUS-FRAME after reading an event typed at FRAME.\n\
  964. \n\
  965. If FOCUS-FRAME is omitted or nil, any existing redirection is\n\
  966. cancelled, and the frame again receives its own keystrokes.\n\
  967. \n\
  968. Focus redirection is useful for temporarily redirecting keystrokes to\n\
  969. a surrogate minibuffer frame when a frame doesn't have its own\n\
  970. minibuffer window.\n\
  971. \n\
  972. A frame's focus redirection can be changed by select-frame.  If frame\n\
  973. FOO is selected, and then a different frame BAR is selected, any\n\
  974. frames redirecting their focus to FOO are shifted to redirect their\n\
  975. focus to BAR.  This allows focus redirection to work properly when the\n\
  976. user switches from one frame to another using `select-window'.\n\
  977. \n\
  978. This means that a frame whose focus is redirected to itself is treated\n\
  979. differently from a frame whose focus is redirected to nil; the former\n\
  980. is affected by select-frame, while the latter is not.\n\
  981. \n\
  982. The redirection lasts until `redirect-frame-focus' is called to change it.")
  983.   (frame, focus_frame)
  984.     Lisp_Object frame, focus_frame;
  985. {
  986.   /* Note that we don't check for a live frame here.  It's reasonable
  987.      to redirect the focus of a frame you're about to delete, if you
  988.      know what other frame should receive those keystrokes.  */
  989.   CHECK_FRAME (frame, 0);
  990.  
  991.   if (! NILP (focus_frame))
  992.     CHECK_LIVE_FRAME (focus_frame, 1);
  993.  
  994.   XFRAME (frame)->focus_frame = focus_frame;
  995.  
  996.   /* I think this should be done with a hook.  */
  997. #ifdef HAVE_X_WINDOWS
  998.   if (!NILP (focus_frame) && ! EQ (focus_frame, frame)
  999.       && FRAME_X_P (XFRAME (focus_frame)))
  1000.     Ffocus_frame (focus_frame);
  1001. #endif
  1002.  
  1003.   if (frame_rehighlight_hook)
  1004.     (*frame_rehighlight_hook) ();
  1005.   
  1006.   return Qnil;
  1007. }
  1008.  
  1009.  
  1010. DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
  1011.   "Return the frame to which FRAME's keystrokes are currently being sent.\n\
  1012. This returns nil if FRAME's focus is not redirected.\n\
  1013. See `redirect-frame-focus'.")
  1014.   (frame)
  1015.     Lisp_Object frame;
  1016. {
  1017.   CHECK_LIVE_FRAME (frame, 0);
  1018.  
  1019.   return FRAME_FOCUS_FRAME (XFRAME (frame));
  1020. }
  1021.  
  1022.  
  1023.  
  1024. Lisp_Object
  1025. get_frame_param (frame, prop)
  1026.      register struct frame *frame;
  1027.      Lisp_Object prop;
  1028. {
  1029.   register Lisp_Object tem;
  1030.  
  1031.   tem = Fassq (prop, frame->param_alist);
  1032.   if (EQ (tem, Qnil))
  1033.     return tem;
  1034.   return Fcdr (tem);
  1035. }
  1036.  
  1037. void
  1038. store_in_alist (alistptr, prop, val)
  1039.      Lisp_Object *alistptr, val;
  1040.      Lisp_Object prop;
  1041. {
  1042.   register Lisp_Object tem;
  1043.  
  1044.   tem = Fassq (prop, *alistptr);
  1045.   if (EQ (tem, Qnil))
  1046.     *alistptr = Fcons (Fcons (prop, val), *alistptr);
  1047.   else
  1048.     Fsetcdr (tem, val);
  1049. }
  1050.  
  1051. void
  1052. store_frame_param (f, prop, val)
  1053.      struct frame *f;
  1054.      Lisp_Object prop, val;
  1055. {
  1056.   register Lisp_Object tem;
  1057.  
  1058.   tem = Fassq (prop, f->param_alist);
  1059.   if (EQ (tem, Qnil))
  1060.     f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
  1061.   else
  1062.     Fsetcdr (tem, val);
  1063.  
  1064.   if (EQ (prop, Qminibuffer)
  1065.       && XTYPE (val) == Lisp_Window)
  1066.     {
  1067.       if (! MINI_WINDOW_P (XWINDOW (val)))
  1068.     error ("Surrogate minibuffer windows must be minibuffer windows.");
  1069.  
  1070.       if (FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
  1071.     error ("can't change the surrogate minibuffer of a frame with its own minibuffer");
  1072.  
  1073.       /* Install the chosen minibuffer window, with proper buffer.  */
  1074.       f->minibuffer_window = val;
  1075.     }
  1076. }
  1077.  
  1078. DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
  1079.   "Return the parameters-alist of frame FRAME.\n\
  1080. It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.\n\
  1081. The meaningful PARMs depend on the kind of frame.\n\
  1082. If FRAME is omitted, return information on the currently selected frame.")
  1083.   (frame)
  1084.      Lisp_Object frame;
  1085. {
  1086.   Lisp_Object alist;
  1087.   struct frame *f;
  1088.  
  1089.   if (EQ (frame, Qnil))
  1090.     f = selected_frame;
  1091.   else
  1092.     {
  1093.       CHECK_FRAME (frame, 0);
  1094.       f = XFRAME (frame);
  1095.     }
  1096.  
  1097.   if (f->display.nothing == 0)
  1098.     return Qnil;
  1099.  
  1100.   alist = Fcopy_alist (f->param_alist);
  1101.   store_in_alist (&alist, Qname, f->name);
  1102.   store_in_alist (&alist, Qheight, make_number (f->height));
  1103.   store_in_alist (&alist, Qwidth, make_number (f->width));
  1104.   store_in_alist (&alist, Qmodeline, (f->wants_modeline ? Qt : Qnil));
  1105.   store_in_alist (&alist, Qminibuffer,
  1106.           (! FRAME_HAS_MINIBUF_P (f) ? Qnil
  1107.            : (FRAME_MINIBUF_ONLY_P (f) ? Qonly
  1108.                    : FRAME_MINIBUF_WINDOW (f))));
  1109.   store_in_alist (&alist, Qunsplittable, (f->no_split ? Qt : Qnil));
  1110.   store_in_alist (&alist, Qmenu_bar_lines, (FRAME_MENU_BAR_LINES (f)));
  1111.  
  1112.   /* I think this should be done with a hook.  */
  1113. #ifdef HAVE_X_WINDOWS
  1114.   if (FRAME_X_P (f))
  1115.     x_report_frame_params (f, &alist);
  1116. #endif
  1117.   return alist;
  1118. }
  1119.  
  1120. DEFUN ("modify-frame-parameters", Fmodify_frame_parameters, 
  1121.        Smodify_frame_parameters, 2, 2, 0,
  1122.   "Modify the parameters of frame FRAME according to ALIST.\n\
  1123. ALIST is an alist of parameters to change and their new values.\n\
  1124. Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.\n\
  1125. The meaningful PARMs depend on the kind of frame; undefined PARMs are ignored.")
  1126.   (frame, alist)
  1127.      Lisp_Object frame, alist;
  1128. {
  1129.   FRAME_PTR f;
  1130. #if 0
  1131.   register Lisp_Object tail, prop, val, elt;
  1132. #endif
  1133.  
  1134.   if (EQ (frame, Qnil))
  1135.     f = selected_frame;
  1136.   else
  1137.     {
  1138.       CHECK_LIVE_FRAME (frame, 0);
  1139.       f = XFRAME (frame);
  1140.     }
  1141.  
  1142.   /* I think this should be done with a hook.  */
  1143. #ifdef HAVE_X_WINDOWS
  1144.   if (FRAME_X_P (f))
  1145. #if 1
  1146.     x_set_frame_parameters (f, alist);
  1147. #else
  1148.     for (tail = alist; !EQ (tail, Qnil); tail = Fcdr (tail))
  1149.       {
  1150.     elt = Fcar (tail);
  1151.     prop = Fcar (elt);
  1152.     val = Fcdr (elt);
  1153.     x_set_frame_param (f, prop, val, get_frame_param (f, prop));
  1154.     store_frame_param (f, prop, val);
  1155.       }
  1156. #endif
  1157. #endif
  1158.  
  1159.   return Qnil;
  1160. }
  1161.  
  1162. DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
  1163.   0, 1, 0,
  1164.   "Height in pixels of a line in the font in frame FRAME.\n\
  1165. If FRAME is omitted, the selected frame is used.\n\
  1166. For a terminal frame, the value is always 1.")
  1167.   (frame)
  1168.      Lisp_Object frame;
  1169. {
  1170.   struct frame *f;
  1171.  
  1172.   if (NILP (frame))
  1173.     f = selected_frame;
  1174.   else
  1175.     {
  1176.       CHECK_FRAME (frame, 0);
  1177.       f = XFRAME (frame);
  1178.     }
  1179.  
  1180. #ifdef HAVE_X_WINDOWS
  1181.   if (FRAME_X_P (f))
  1182.     return make_number (x_char_height (f));
  1183.   else
  1184. #endif
  1185.     return make_number (1);
  1186. }
  1187.  
  1188.  
  1189. DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
  1190.   0, 1, 0,
  1191.   "Width in pixels of characters in the font in frame FRAME.\n\
  1192. If FRAME is omitted, the selected frame is used.\n\
  1193. The width is the same for all characters, because\n\
  1194. currently Emacs supports only fixed-width fonts.\n\
  1195. For a terminal screen, the value is always 1.")
  1196.   (frame)
  1197.      Lisp_Object frame;
  1198. {
  1199.   struct frame *f;
  1200.  
  1201.   if (NILP (frame))
  1202.     f = selected_frame;
  1203.   else
  1204.     {
  1205.       CHECK_FRAME (frame, 0);
  1206.       f = XFRAME (frame);
  1207.     }
  1208.  
  1209. #ifdef HAVE_X_WINDOWS
  1210.   if (FRAME_X_P (f))
  1211.     return make_number (x_char_width (f));
  1212.   else
  1213. #endif
  1214.     return make_number (1);
  1215. }
  1216.  
  1217. DEFUN ("frame-pixel-height", Fframe_pixel_height, 
  1218.        Sframe_pixel_height, 0, 1, 0,
  1219.   "Return a FRAME's height in pixels.\n\
  1220. For a terminal frame, the result really gives the height in characters.\n\
  1221. If FRAME is omitted, the selected frame is used.")
  1222.   (frame)
  1223.      Lisp_Object frame;
  1224. {
  1225.   struct frame *f;
  1226.  
  1227.   if (NILP (frame))
  1228.     f = selected_frame;
  1229.   else
  1230.     {
  1231.       CHECK_FRAME (frame, 0);
  1232.       f = XFRAME (frame);
  1233.     }
  1234.  
  1235. #ifdef HAVE_X_WINDOWS
  1236.   if (FRAME_X_P (f))
  1237.     return make_number (x_pixel_height (f));
  1238.   else
  1239. #endif
  1240.     return make_number (FRAME_HEIGHT (f));
  1241. }
  1242.  
  1243. DEFUN ("frame-pixel-width", Fframe_pixel_width, 
  1244.        Sframe_pixel_width, 0, 1, 0,
  1245.   "Return FRAME's width in pixels.\n\
  1246. For a terminal frame, the result really gives the width in characters.\n\
  1247. If FRAME is omitted, the selected frame is used.")
  1248.   (frame)
  1249.      Lisp_Object frame;
  1250. {
  1251.   struct frame *f;
  1252.  
  1253.   if (NILP (frame))
  1254.     f = selected_frame;
  1255.   else
  1256.     {
  1257.       CHECK_FRAME (frame, 0);
  1258.       f = XFRAME (frame);
  1259.     }
  1260.  
  1261. #ifdef HAVE_X_WINDOWS
  1262.   if (FRAME_X_P (f))
  1263.     return make_number (x_pixel_width (f));
  1264.   else
  1265. #endif
  1266.     return make_number (FRAME_WIDTH (f));
  1267. }
  1268.  
  1269. DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
  1270.   "Specify that the frame FRAME has LINES lines.\n\
  1271. Optional third arg non-nil means that redisplay should use LINES lines\n\
  1272. but that the idea of the actual height of the frame should not be changed.")
  1273.   (frame, rows, pretend)
  1274.      Lisp_Object frame, rows, pretend;
  1275. {
  1276.   register struct frame *f;
  1277.  
  1278.   CHECK_NUMBER (rows, 0);
  1279.   if (NILP (frame))
  1280.     f = selected_frame;
  1281.   else
  1282.     {
  1283.       CHECK_LIVE_FRAME (frame, 0);
  1284.       f = XFRAME (frame);
  1285.     }
  1286.  
  1287.   /* I think this should be done with a hook.  */
  1288. #ifdef HAVE_X_WINDOWS
  1289.   if (FRAME_X_P (f))
  1290.     {
  1291.       if (XINT (rows) != f->width)
  1292.     x_set_window_size (f, f->width, XINT (rows));
  1293.     }
  1294.   else
  1295. #endif
  1296.     change_frame_size (f, XINT (rows), 0, !NILP (pretend), 0);
  1297.   return Qnil;
  1298. }
  1299.  
  1300. DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
  1301.   "Specify that the frame FRAME has COLS columns.\n\
  1302. Optional third arg non-nil means that redisplay should use COLS columns\n\
  1303. but that the idea of the actual width of the frame should not be changed.")
  1304.   (frame, cols, pretend)
  1305.      Lisp_Object frame, cols, pretend;
  1306. {
  1307.   register struct frame *f;
  1308.   CHECK_NUMBER (cols, 0);
  1309.   if (NILP (frame))
  1310.     f = selected_frame;
  1311.   else
  1312.     {
  1313.       CHECK_LIVE_FRAME (frame, 0);
  1314.       f = XFRAME (frame);
  1315.     }
  1316.  
  1317.   /* I think this should be done with a hook.  */
  1318. #ifdef HAVE_X_WINDOWS
  1319.   if (FRAME_X_P (f))
  1320.     {
  1321.       if (XINT (cols) != f->width)
  1322.     x_set_window_size (f, XINT (cols), f->height);
  1323.     }
  1324.   else
  1325. #endif
  1326.     change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0);
  1327.   return Qnil;
  1328. }
  1329.  
  1330. DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
  1331.   "Sets size of FRAME to COLS by ROWS, measured in characters.")
  1332.   (frame, cols, rows)
  1333.      Lisp_Object frame, cols, rows;
  1334. {
  1335.   register struct frame *f;
  1336.  
  1337.   CHECK_LIVE_FRAME (frame, 0);
  1338.   CHECK_NUMBER (cols, 2);
  1339.   CHECK_NUMBER (rows, 1);
  1340.   f = XFRAME (frame);
  1341.  
  1342.   /* I think this should be done with a hook.  */
  1343. #ifdef HAVE_X_WINDOWS
  1344.   if (FRAME_X_P (f))
  1345.     {
  1346.       if (XINT (rows) != f->height || XINT (cols) != f->width)
  1347.     x_set_window_size (f, XINT (cols), XINT (rows));
  1348.     }
  1349.   else
  1350. #endif
  1351.     change_frame_size (f, XINT (rows), XINT (cols), 0, 0);
  1352.  
  1353.   return Qnil;
  1354. }
  1355.  
  1356. DEFUN ("set-frame-position", Fset_frame_position, 
  1357.        Sset_frame_position, 3, 3, 0,
  1358.   "Sets position of FRAME in pixels to XOFFSET by YOFFSET.\n\
  1359. If XOFFSET or YOFFSET are negative, they are interpreted relative to\n\
  1360. the leftmost or bottommost position FRAME could occupy without going\n\
  1361. off the screen.")
  1362.   (frame, xoffset, yoffset)
  1363.      Lisp_Object frame, xoffset, yoffset;
  1364. {
  1365.   register struct frame *f;
  1366.  
  1367.   CHECK_LIVE_FRAME (frame, 0);
  1368.   CHECK_NUMBER (xoffset, 1);
  1369.   CHECK_NUMBER (yoffset, 2);
  1370.   f = XFRAME (frame);
  1371.  
  1372.   /* I think this should be done with a hook.  */
  1373. #ifdef HAVE_X_WINDOWS
  1374.   if (FRAME_X_P (f))
  1375.     x_set_offset (f, XINT (xoffset), XINT (yoffset));
  1376. #endif
  1377.  
  1378.   return Qt;
  1379. }
  1380.  
  1381.  
  1382. _VOID_
  1383. choose_minibuf_frame ()
  1384. {
  1385.   /* For lowest-level minibuf, put it on currently selected frame
  1386.      if frame has a minibuffer.  */
  1387.  
  1388.   if (minibuf_level == 0
  1389.       && selected_frame != 0
  1390.       && !EQ (minibuf_window, selected_frame->minibuffer_window))
  1391.     {
  1392.       /* I don't think that any frames may validly have a null minibuffer
  1393.      window anymore.  */
  1394.       if (NILP (selected_frame->minibuffer_window))
  1395.     abort ();
  1396.  
  1397.       Fset_window_buffer (selected_frame->minibuffer_window,
  1398.               XWINDOW (minibuf_window)->buffer);
  1399.       minibuf_window = selected_frame->minibuffer_window;
  1400.     }
  1401. }
  1402.  
  1403. _VOID_
  1404. syms_of_frame ()
  1405. {
  1406.   /*&&& init symbols here &&&*/
  1407.   Qframep = intern ("framep");
  1408.   staticpro (&Qframep);
  1409.   Qframe_live_p = intern ("frame-live-p");
  1410.   staticpro (&Qframe_live_p);
  1411.   Qheight = intern ("height");
  1412.   staticpro (&Qheight);
  1413.   Qicon = intern ("icon");
  1414.   staticpro (&Qicon);
  1415.   Qminibuffer = intern ("minibuffer");
  1416.   staticpro (&Qminibuffer);
  1417.   Qmodeline = intern ("modeline");
  1418.   staticpro (&Qmodeline);
  1419.   Qname = intern ("name");
  1420.   staticpro (&Qname);
  1421.   Qonly = intern ("only");
  1422.   staticpro (&Qonly);
  1423.   Qunsplittable = intern ("unsplittable");
  1424.   staticpro (&Qunsplittable);
  1425.   Qwidth = intern ("width");
  1426.   staticpro (&Qwidth);
  1427.   Qx = intern ("x");
  1428.   staticpro (&Qx);
  1429.   Qmenu_bar_lines = intern ("menu-bar-lines");
  1430.   staticpro (&Qmenu_bar_lines);
  1431.  
  1432.   staticpro (&Vframe_list);
  1433.  
  1434.   DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
  1435.     "The initial frame-object, which represents Emacs's stdout.");
  1436.  
  1437.   DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
  1438.     "Non-nil if all of emacs is iconified and frame updates are not needed.");
  1439.   Vemacs_iconified = Qnil;
  1440.  
  1441.   DEFVAR_LISP ("default-minibuffer-frame", &Vdefault_minibuffer_frame,
  1442.     "Minibufferless frames use this frame's minibuffer.\n\
  1443. \n\
  1444. Emacs cannot create minibufferless frames unless this is set to an\n\
  1445. appropriate surrogate.\n\
  1446. \n\
  1447. Emacs consults this variable only when creating minibufferless\n\
  1448. frames; once the frame is created, it sticks with its assigned\n\
  1449. minibuffer, no matter what this variable is set to.  This means that\n\
  1450. this variable doesn't necessarily say anything meaningful about the\n\
  1451. current set of frames, or where the minibuffer is currently being\n\
  1452. displayed.");
  1453.   Vdefault_minibuffer_frame = Qnil;
  1454.  
  1455.   DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
  1456.     "Alist of default values for frame creation.\n\
  1457. These may be set in your init file, like this:\n\
  1458.   (setq default-frame-alist '((width . 80) (height . 55)))\n\
  1459. These override values given in window system configuration data, like\n\
  1460. X Windows' defaults database.\n\
  1461. For values specific to the first Emacs frame, see `initial-frame-alist'.\n\
  1462. For values specific to the separate minibuffer frame, see\n\
  1463. `minibuffer-frame-alist'.");
  1464.   Vdefault_frame_alist = Qnil;
  1465.  
  1466.   defsubr (&Sframep);
  1467.   defsubr (&Sframe_live_p);
  1468.   defsubr (&Shandle_switch_frame);
  1469.   defsubr (&Sselect_frame);
  1470.   defsubr (&Sselected_frame);
  1471.   defsubr (&Swindow_frame);
  1472.   defsubr (&Sframe_root_window);
  1473.   defsubr (&Sframe_selected_window);
  1474.   defsubr (&Sframe_list);
  1475.   defsubr (&Snext_frame);
  1476.   defsubr (&Sdelete_frame);
  1477.   defsubr (&Smouse_position);
  1478.   defsubr (&Sset_mouse_position);
  1479. #if 0
  1480.   defsubr (&Sframe_configuration);
  1481.   defsubr (&Srestore_frame_configuration);
  1482. #endif
  1483.   defsubr (&Smake_frame_visible);
  1484.   defsubr (&Smake_frame_invisible);
  1485.   defsubr (&Siconify_frame);
  1486.   defsubr (&Sframe_visible_p);
  1487.   defsubr (&Svisible_frame_list);
  1488.   defsubr (&Sraise_frame);
  1489.   defsubr (&Slower_frame);
  1490.   defsubr (&Sredirect_frame_focus);
  1491.   defsubr (&Sframe_focus);
  1492.   defsubr (&Sframe_parameters);
  1493.   defsubr (&Smodify_frame_parameters);
  1494.   defsubr (&Sframe_char_height);
  1495.   defsubr (&Sframe_char_width);
  1496.   defsubr (&Sframe_pixel_height);
  1497.   defsubr (&Sframe_pixel_width);
  1498.   defsubr (&Sset_frame_height);
  1499.   defsubr (&Sset_frame_width);
  1500.   defsubr (&Sset_frame_size);
  1501.   defsubr (&Sset_frame_position);
  1502. }
  1503.  
  1504. _VOID_
  1505. keys_of_frame ()
  1506. {
  1507.   initial_define_lispy_key (global_map, "switch-frame", "handle-switch-frame");
  1508. }
  1509.  
  1510. #else /* not MULTI_FRAME */
  1511.  
  1512. /* If we're not using multi-frame stuff, we still need to provide some
  1513.    support functions.  */
  1514.  
  1515. /* Unless this function is defined, providing set-frame-height and
  1516.    set-frame-width doesn't help compatibility any, since they both
  1517.    want this as their first argument.  */
  1518. DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
  1519.   "Return the frame that is now selected.")
  1520.   ()
  1521. {
  1522.   Lisp_Object tem;
  1523.   XFASTINT (tem) = 0;
  1524.   return tem;
  1525. }
  1526. DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
  1527.   "Return non-nil if OBJECT is a frame.\n\
  1528. Value is t for a termcap frame (a character-only terminal),\n\
  1529. `x' for an Emacs frame that is really an X window.\n\
  1530. Also see `live-frame-p'.")
  1531.   (object)
  1532.      Lisp_Object object;
  1533. {
  1534.   return Qnil;
  1535. }
  1536.  
  1537. DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
  1538.   "Specify that the frame FRAME has LINES lines.\n\
  1539. Optional third arg non-nil means that redisplay should use LINES lines\n\
  1540. but that the idea of the actual height of the frame should not be changed.")
  1541.   (frame, rows, pretend)
  1542.      Lisp_Object frame, rows, pretend;
  1543. {
  1544.   CHECK_NUMBER (rows, 0);
  1545.  
  1546.   change_frame_size (0, XINT (rows), 0, !NILP (pretend), 0);
  1547.   return Qnil;
  1548. }
  1549.  
  1550. DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
  1551.   "Specify that the frame FRAME has COLS columns.\n\
  1552. Optional third arg non-nil means that redisplay should use COLS columns\n\
  1553. but that the idea of the actual width of the frame should not be changed.")
  1554.   (frame, cols, pretend)
  1555.      Lisp_Object frame, cols, pretend;
  1556. {
  1557.   CHECK_NUMBER (cols, 0);
  1558.  
  1559.   change_frame_size (0, 0, XINT (cols), !NILP (pretend), 0);
  1560.   return Qnil;
  1561. }
  1562.  
  1563. DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
  1564.   "Sets size of FRAME to COLS by ROWS, measured in characters.")
  1565.   (frame, cols, rows)
  1566.      Lisp_Object frame, cols, rows;
  1567. {
  1568.   CHECK_NUMBER (cols, 2);
  1569.   CHECK_NUMBER (rows, 1);
  1570.  
  1571.   change_frame_size (0, XINT (rows), XINT (cols), 0, 0);
  1572.  
  1573.   return Qnil;
  1574. }
  1575.  
  1576. DEFUN ("frame-height", Fframe_height, Sframe_height, 0, 1, 0,
  1577.   "Return number of lines available for display on FRAME.\n\
  1578. If FRAME is omitted, describe the currently selected frame.")
  1579.   (frame)
  1580.     Lisp_Object frame;
  1581. {
  1582.   return make_number (FRAME_HEIGHT (selected_frame));
  1583. }
  1584.  
  1585. DEFUN ("frame-width", Fframe_width, Sframe_width, 0, 1, 0,
  1586.   "Return number of columns available for display on FRAME.\n\
  1587. If FRAME is omitted, describe the currently selected frame.")
  1588.   (frame)
  1589.     Lisp_Object frame;
  1590. {
  1591.   return make_number (FRAME_WIDTH (selected_frame));
  1592. }
  1593.  
  1594. DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
  1595.   0, 1, 0,
  1596.   "Height in pixels of a line in the font in frame FRAME.\n\
  1597. If FRAME is omitted, the selected frame is used.\n\
  1598. For a terminal frame, the value is always 1.")
  1599.   (frame)
  1600.      Lisp_Object frame;
  1601. {
  1602.   return make_number (1);
  1603. }
  1604.  
  1605.  
  1606. DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
  1607.   0, 1, 0,
  1608.   "Width in pixels of characters in the font in frame FRAME.\n\
  1609. If FRAME is omitted, the selected frame is used.\n\
  1610. The width is the same for all characters, because\n\
  1611. currently Emacs supports only fixed-width fonts.\n\
  1612. For a terminal screen, the value is always 1.")
  1613.   (frame)
  1614.      Lisp_Object frame;
  1615. {
  1616.   return make_number (1);
  1617. }
  1618.  
  1619. DEFUN ("frame-pixel-height", Fframe_pixel_height, 
  1620.        Sframe_pixel_height, 0, 1, 0,
  1621.   "Return FRAME's height in pixels.\n\
  1622. For a terminal frame, the result really gives the height in characters.\n\
  1623. If FRAME is omitted, the selected frame is used.")
  1624.   (frame)
  1625.      Lisp_Object frame;
  1626. {
  1627.   return make_number (FRAME_HEIGHT (f));
  1628. }
  1629.  
  1630. DEFUN ("frame-pixel-width", Fframe_pixel_width, 
  1631.        Sframe_pixel_width, 0, 1, 0,
  1632.   "Return FRAME's width in pixels.\n\
  1633. For a terminal frame, the result really gives the width in characters.\n\
  1634. If FRAME is omitted, the selected frame is used.")
  1635.   (frame)
  1636.      Lisp_Object frame;
  1637. {
  1638.   return make_number (FRAME_WIDTH (f));
  1639. }
  1640.  
  1641. /* These are for backward compatibility with Emacs 18.  */
  1642.  
  1643. DEFUN ("set-screen-height", Fset_screen_height, Sset_screen_height, 1, 2, 0,
  1644.   "Tell redisplay that the screen has LINES lines.\n\
  1645. Optional second arg non-nil means that redisplay should use LINES lines\n\
  1646. but that the idea of the actual height of the screen should not be changed.")
  1647.   (lines, pretend)
  1648.      Lisp_Object lines, pretend;
  1649. {
  1650.   CHECK_NUMBER (lines, 0);
  1651.  
  1652.   change_frame_size (0, XINT (lines), 0, !NILP (pretend), 0);
  1653.   return Qnil;
  1654. }
  1655.  
  1656. DEFUN ("set-screen-width", Fset_screen_width, Sset_screen_width, 1, 2, 0,
  1657.   "Tell redisplay that the screen has COLS columns.\n\
  1658. Optional second arg non-nil means that redisplay should use COLS columns\n\
  1659. but that the idea of the actual width of the screen should not be changed.")
  1660.   (cols, pretend)
  1661.      Lisp_Object cols, pretend;
  1662. {
  1663.   CHECK_NUMBER (cols, 0);
  1664.  
  1665.   change_frame_size (0, 0, XINT (cols), !NILP (pretend), 0);
  1666.   return Qnil;
  1667. }
  1668.  
  1669. _VOID_
  1670. syms_of_frame ()
  1671. {
  1672.   defsubr (&Sselected_frame);
  1673.   defsubr (&Sframep);
  1674.   defsubr (&Sframe_char_height);
  1675.   defsubr (&Sframe_char_width);
  1676.   defsubr (&Sframe_pixel_height);
  1677.   defsubr (&Sframe_pixel_width);
  1678.   defsubr (&Sset_frame_height);
  1679.   defsubr (&Sset_frame_width);
  1680.   defsubr (&Sset_frame_size);
  1681.   defsubr (&Sset_screen_height);
  1682.   defsubr (&Sset_screen_width);
  1683.   defsubr (&Sframe_height);
  1684.   Ffset (intern ("screen-height"), intern ("frame-height"));
  1685.   defsubr (&Sframe_width);
  1686.   Ffset (intern ("screen-width"), intern ("frame-width"));
  1687. }
  1688.  
  1689. _VOID_
  1690. keys_of_frame ()
  1691. {
  1692. }
  1693.  
  1694. #endif /* not MULTI_FRAME */
  1695.